lib/commit: Rework a conditional set for clarity and Coverity
authorColin Walters <walters@verbum.org>
Mon, 31 Jul 2017 16:35:58 +0000 (12:35 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 2 Aug 2017 15:34:16 +0000 (15:34 +0000)
Coverity complained that the `else if (bytes_read == 0)` was dead
code if we happened to find it was already false when testing
`else if (G_UNLIKELY (bytes_read == 0 ...`.

There was nothing wrong with the logic, but let's rework it to
only test the value once; I think it does end up nicer anyways.

Coverity CID: 1452186

Closes: #1037
Approved by: jlebon

src/libostree/ostree-repo-commit.c

index 1d3d6840e2e72c3690ad2c679e8f9067586277aa..ab348311e7450a01de39c6bae93ce216f5e68aa1 100644 (file)
@@ -485,10 +485,13 @@ create_regular_tmpfile_linkable_with_content (OstreeRepo *self,
             g_input_stream_read (input, buf, MIN (remaining, sizeof (buf)), cancellable, error);
           if (bytes_read < 0)
             return FALSE;
-          else if (G_UNLIKELY (bytes_read == 0 && remaining > 0))
-            return glnx_throw (error, "Unexpected EOF with %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT " bytes remaining", remaining, length);
           else if (bytes_read == 0)
-            break;
+            {
+              if (G_UNLIKELY (remaining > 0))
+                return glnx_throw (error, "Unexpected EOF with %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT " bytes remaining", remaining, length);
+              else
+                break;
+            }
           if (glnx_loop_write (tmpf.fd, buf, bytes_read) < 0)
             return glnx_throw_errno_prefix (error, "write");
           remaining -= bytes_read;